package daily;

import java.util.Arrays;

/**
 * @author MtRider
 * @version 1.0
 * @description 反转字符串
 * <p>
 * 输入：s = ["h","e","l","l","o"]
 * 输出：["o","l","l","e","h"]
 * <p>
 * 输入：s = ["H","a","n","n","a","h"]
 * 输出：["h","a","n","n","a","H"]
 * @GiteeAndGithub MtRider
 * @date 2022/4/24 9:50
 */
public class demo11 {
    public static void main(String[] args) {
        char [] s={'H','a','n','n','a','h'};
        reverseString(s);
    }

    //StringBuffer接收反转
    public static void reverseString(char[] s) {
        StringBuffer buffer = new StringBuffer();
        for (char c : s) {
            buffer.append(c);
        }
        buffer.reverse();

        for (int i = 0; i < s.length; i++) {
            s[i]=buffer.charAt(i);
        }
    }

    //对称交换
    public static void reverseString2(char[] s) {
        int length=s.length;
        char temp;
        for (int i = 0; i < s.length/2; i++) {
            temp=s[i];
            s[i]=s[length-1-i];
            s[length-1-i]=temp;
        }
    }

}
